package javase.array;

import java.util.Arrays;

public class MaoPao {
    public static void main(String[] args) {
//        int[] arr = {999, 18888, 5555, 2222, 86, 5, 74, 115, 81164, 5248, 1111111, 55, 81654, 146852, 5119846, 18, 2121548, 50000};
        int[] arr = {22, 1, 2, 3};
        int[] arr1 = {11, 2222222, 333, 4, 48, 22, 1, 2, 3};
        for (int i = 0; i < arr.length - 1; i++) {
            boolean sign = false;
            for (int j = 0; j < arr.length - 1 - i; j++) {
                if (arr[j] > arr[j + 1]) {
                    int temp = arr[j + 1];
                    arr[j + 1] = arr[j];
                    arr[j] = temp;
                    sign = true;
                }
            }
            if (sign == false) {
                break;
            }
        }
        System.out.println("Arrays.equals(arr,arr1) = " + Arrays.equals(arr, arr1));
        Arrays.sort(arr1);
        System.out.println(Arrays.toString(arr1));
        System.out.println("Arrays.binarySearch(arr1,2) = " + Arrays.binarySearch(arr1, 333));

        /*二分查找*/
        int left = 0;
        int right = arr1.length-1;
        int target = 11;
        while (left<=right) {
            int middle = (left + right) / 2;
            if (arr1[middle] > target) {
                right = middle - 1;
            } else if (arr1[middle] < target) {
                left = middle + 1;
            } else if (arr1[middle] == target) {
                System.out.println(middle+1);
                break;
            }
        }
         if(left>right){
            System.out.println("没有");
        }

    }


}
